﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kaesoft.Caja.Views
{
    /// <summary>
    /// Class EntityList.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class EntityList<T> : ObservableCollection<T>
    {
        /// <summary>
        /// Occurs when [collection clearing].
        /// </summary>
        public event EventHandler CollectionClearing;

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityList{T}"/> class.
        /// </summary>
        /// <param name="values">The values.</param>
        public EntityList(IEnumerable<T> values)
            : base(values)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityList{T}"/> class.
        /// </summary>
        public EntityList()
            : base()
        {
        }

        /// <summary>
        /// Removes all elements from the <see cref="T:System.Collections.ObjectModel.Collection`1" />.
        /// </summary>
        public void Clear()
        {
            if (this.Count > 0)
            {
                var oldList = new EntityList<T>(this);
                base.Clear();
                var collectionClearing = CollectionClearing;
                if (collectionClearing != null)
                    collectionClearing(oldList, new EventArgs());
            }
        }
    }
}
